mui.previewImage();
angular.module('myApp', ['infinite-scroll']);
var allTimes = 0,
	wrap = document.getElementById("wrap");
var state = 0;
var gouwuche = false;
var maxWidth = document.body.clientWidth;
var divs = document.getElementsByClassName("swiper-slide");
for (var i = 0; i < divs.length; i++) {
	divs[i].style.height = maxWidth * 0.9 + "px";
}

//控制轮播图
function init() {
	var mySwiper = new Swiper('.swiper-container', {
		autoplay: 3000,
		direction: 'horizontal',
		loop: false,
		speed: 300,
		pagination: '.swiper-pagination',
	});
}
var circle = document.getElementById("circle");
// 控制商品数量的变化
function Num(num) {
	var textnum = document.getElementById("textnum");
	var numI = parseFloat(textnum.value) + num;
	if (numI < 1) {
		return;
	}
	textnum.value = numI;
}
var content = {
	"color": "",
	"size": "",
	"spec": "",
	"model": ""
};
var cesi = [],
	color = [],
	size = [],
	model = [],
	spec = [];
var sureArguments = {};
var paramerState = null;

function CMeau(meau) {
	if (meau.style.display == "none" || meau.style.display == "") {
		meau.style.display = "block";
		setTimeout(function() {
			document.getElementById("d1").style.transform = "translate3d(0,0,0)";
			document.getElementById("d1").style.webkitTransform = "translate3d(0,0,0)";
		}, 20);
		wrap.style.height = document.documentElement.clientHeight + "px";
		//wrap.style.overflow = "hidden";
	} else {
		document.getElementById("d1").style.transform = "translate3d(0,100%,0)";
		document.getElementById("d1").style.webkitTransform = "translate3d(0,100%,0)";
		meau.style.display = "none";
		wrap.style.height = "auto";
	}
}

function product($scope, $http) {
	$scope.zhedie = function() {
		if (state == 0) {
			document.getElementById("fangshi").className = 'fangshi huanhang';
			state = 1;
		} else {
			document.getElementById("fangshi").className = 'fangshi yinchang';
			state = 0;
		}
	}
	$scope.sure = function(meau) {
			sureArguments = {
				"color": content.color,
				"size": content.size,
				"spec": content.spec,
				"model": content.model
			};
			$scope.color = content.color;
			$scope.size = content.size;
			$scope.spec = content.spec;
			$scope.models = content.model;
			content = {
				"color": "",
				"size": "",
				"spec": "",
				"model": ""
			};
			CMeau(document.getElementById('mask'));
			document.getElementById("btnsure").disabled = true;
			if ($scope.colorlists.length > 0) {
				huifu($scope.colorlists)
			}
			if ($scope.sizelists.length > 0) {
				huifu($scope.sizelists);
			}
			if ($scope.modellists.length > 0) {
				huifu($scope.modellists);
			}
			if ($scope.speclists.length > 0) {
				huifu($scope.speclists);
			}
			//是否要直接加入购物车
			if (paramerState == 'addBuycar') {
				$scope.addBuycar();
			}
			//是否直接购买 
			if (paramerState == 'buyNow') {
				$scope.buyNow();
			}
		}
		//商品默认数量
	$scope.productNum = '1';
	goodsId = readData(localStorage.goodsId);
	$scope.guanzhustatus;
	//商品详情
	urlPro = getUrl("18detail");
	headerPro = getHeader();
	paramsPro = 'id=' + goodsId + '&accountId=' + readData(localStorage.account) + '&indexpage=0&pageSize=1';
	$http({
		method: 'POST',
		url: urlPro,
		headers: headerPro,
		timeout: 10000,
		//cache: true,
		data: paramsPro
	}).success(function(data, status, headers, config) {
		if (data.obj) {
			//console.log(JSON.stringify(data.obj));
			$scope.products = data.obj.product;
			$scope.promotionList = data.obj.promotionList;
			//关注状态
			if (data.obj.status == 0) {
				$scope.status = "加关注";
				document.getElementById("statusImg").src = "../../image/shopping/weiguanzhu.png";
				$scope.guanzhustatus = 1;
			} else {
				$scope.status = "取消关注";
				$scope.guanzhustatus = 2;
				document.getElementById("statusImg").src = "../../image/shopping/guanzhu.png";
			}
			$scope.paymodels = data.obj.product.payModels;
			if ($scope.products.priceName) { //专享价显示
				$scope.products.hide = true;
			} else {
				$scope.products.hide = false;
			}
			if ($scope.products.deposit) {
				$scope.products.dingjin = true;
			} else {
				$scope.products.dingjin = false;
			}
			var imgs = data.obj.product['images'];
			var pics = [];
			if (data.obj.product['images']) {
				while (imgs.length > 0 && imgs != 'null') {
					if (imgs.indexOf(',') == -1) {
						pics.push({
							pic: imgs
						});
						imgs = '';
					} else {
						pic1 = imgs.substring(0, imgs.indexOf(','));
						imgs = imgs.substring(imgs.indexOf(',') + 1);
						pics.push({
							pic: pic1
						})
					}
				}
				if (pics[0].pic) { //商品图片存在显示
					$scope.fristPic = pics[0].pic;
				} else { //不存在替换
					$scope.fristPic = '../../image/shopping/small.png';
				}
			} else {
				pic1 = {
					"pic": "../../image/shopping/biger.png"
				};
				$scope.fristPic = '../../image/shopping/small.png';
				pics.push(pic1);
			}
			setTimeout("init()", 50);
			$scope.pics = pics;
			if (data.obj.product.productHTML) {
				document.getElementById("pic").innerHTML = data.obj.product.productHTML;
			}
		} else {
			$scope.products = null;
		};
	}).error(function() {
		console.log("商品详情出错");
	});
	//商品规格
	urlSpec = getUrl("19spec");
	headerSpec = getHeader();
	paramsSpec = 'id=' + goodsId;
	$http({
		method: 'POST',
		url: urlSpec,
		headers: headerSpec,
		timeout: 10000,
		//cache: true,
		data: paramsSpec
	}).success(function(data, status, headers, config) {
		if (data.obj) {
			gouwuche = true;
			cesi = data.obj.list;
			var colorList = [],
				sizeList = [],
				modelList = [],
				specList = [];
			for (var i = 0; i < cesi.length; i++) {
				if (cesi[i].color) {
					colorList.push(cesi[i].color);
				}
				if (cesi[i].size) {
					sizeList.push(cesi[i].size);
				}
				if (cesi[i].spec) {
					specList.push(cesi[i].spec);
				}
				if (cesi[i].model) {
					modelList.push(cesi[i].model);
				}
			}
			$scope.colorlists = getArray(colorList);
			$scope.sizelists = getArray(sizeList);
			$scope.modellists = getArray(modelList);
			$scope.speclists = getArray(specList);
			color = getArray(colorList);
			size = getArray(sizeList);
			model = getArray(modelList);
			spec = getArray(specList);
			if ($scope.colorlists) {
				if ($scope.colorlists.length > 0) {
					if (!$scope.colorlists[0]) {
						$scope.colorHide = false;
					} else {
						$scope.colorHide = true;
					}
				} else {
					$scope.color = ""
					$scope.colorHide = false;
				}
			} else {
				$scope.color = ""
			}
			if ($scope.sizelists) {
				if ($scope.sizelists.length > 0) {
					if (!$scope.sizelists[0]) {
						$scope.sizeHide = false;
					} else {
						$scope.sizeHide = true;
					}
				} else {
					$scope.size = ""
					$scope.sizeHide = false;
				}
			} else {
				$scope.size = ""
			}
			if ($scope.modellists) {
				if ($scope.modellists.length > 0) {
					if (!$scope.modellists[0]) {
						$scope.modelHide = false;
					} else {
						$scope.modelHide = true;
					}
				} else {
					$scope.models = ""
					$scope.modelHide = false;
				}
			} else {
				$scope.models = ""
			}
			if ($scope.speclists) {
				if ($scope.speclists.length > 0) {
					if (!$scope.speclists[0]) {
						$scope.specHide = false;
					} else {
						$scope.specHide = true;
					}
				} else {
					$scope.spec = "";
					$scope.specHide = false;
				}
			} else {
				$scope.spec = "";
			}

		} else {
			$scope.colorlists = [];
			$scope.color = "";
			$scope.sizelists = [];
			$scope.size = "";
			$scope.modelLists = [];
			$scope.models = "";
			$scope.specLists = [];
			$scope.spec = "";
			gouwuche = true;
		};
	}).error(function() {
		if (allTimes == 0) {
			console.log("商品详情商品规格出错");
		}
	});
	//商品评价
	$scope.totalPage = 1;
	$scope.pageindex = 0;
	$scope.comments = [];
	url = getUrl("20comment");
	header = getHeader();
	$scope.loadMore = function() {
		if ($scope.pageindex < $scope.totalPage) {
			params = 'id=' + goodsId + '&indexpage=' + $scope.pageindex + '&pageSize=6';
			$scope.pageindex = $scope.pageindex + 1;
			$http({
				method: 'POST',
				url: url,
				headers: header,
				timeout: 10000,
				//cache: true,
				data: params
			}).success(function(data, status, headers, config) {
				if (data.obj) {
					for (var i in data.obj.list) {
						var array = [];
						for (var j = 0; j < data.obj.list[i].star; j++) {
							array.push("../../image/shopping/pl_dxx.png")
						}
						data.obj.list[i].star = array;
						if (data.obj.list[i].specSize) {
							data.obj.list[i].hidesize = false;
						} else {
							data.obj.list[i].hidesize = true;
						}
						if (data.obj.list[i].specColor) {
							data.obj.list[i].hidecolor = false;
						} else {
							data.obj.list[i].hidecolor = true;
						}
						if (data.obj.list[i].specSpec) {
							data.obj.list[i].hidespec = false;
						} else {
							data.obj.list[i].hidespec = true;
						}
						if (data.obj.list[i].specModel) {
							data.obj.list[i].hidemodel = false;
						} else {
							data.obj.list[i].hidemodel = true;
						}
						$scope.comments.push(data.obj.list[i]);
					}
					for (var i = 0; i < $scope.comments.length; i++) {
						if (!$scope.comments[i].headImg || $scope.comments[i].headImg == 'null') {
							$scope.comments[i].headImg = '../../image/samll.png';
						}
					}
					$scope.totalPage = data.obj.totalpage;
				} else {
					$scope.comments = [];
					$scope.pageindex = $scope.pageindex - 1;
				};
			}).error(function() {
				if (allTimes == 0) {
					console.log("商品详情商品评价出错");
				}
				$scope.pageindex = $scope.pageindex - 1;
			});
		}
	}
	$scope.addBuycar = function() {
		//当前商品加入购物车
		if (!gouwuche)
			return;
		var cont = notSelect();
		if (cont) {
			cont = "请选择" + cont;
			tishi(cont);
			paramerState = 'addBuycar';
		} else {
			goodsAdd(goodsId, $scope.productNum, readData(localStorage.guideId), $scope.size, $scope.color, $scope.models, $scope.spec);
			$scope.goodsNumber();
			mui.toast('商品添加成功');
			paramerState = null;
			//reloadHtml("buyCar.html");
			//刷新购物车数量
			refershBycar();
		}
	}

	function tishi(cont) {
		var meau = document.getElementById('mask');
		mui.toast(cont);
		CMeau(meau)
	}
	document.getElementById('mask').addEventListener("touchmove", function(envnt) {
			var e = event || event;
			var obj = e.target.getAttribute("id");
			if (obj) {
				if (obj == "mask") {
					e.preventDefault()
				}
			}
		})
		//去重
	function getArray(a) {
		var hash = {},
			len = a.length,
			result = [];
		for (var i = 0; i < len; i++) {
			if (!hash[a[i]]) {
				hash[a[i]] = true;
				result.push(a[i]);
			}
		}
		return result;
	}
	$scope.openBuycar = function() {
		mui.openWindow({
			url: 'buyCar.html',
			id: 'buyCar.html',
			waiting: {
				autoShow: false
			}
		});
	}
	$scope.Num = function(num) {
		newNum = parseFloat($scope.productNum)
		if (num == '0') {
			newNum = newNum - 1
		} else {
			newNum = newNum + 1
		}
		if (newNum == 0) {
			return;
		} else {
			$scope.productNum = newNum.toString();
		}
	}
	$scope.selColor = function(values, obj) {
		document.getElementById("btnsure").disabled = false;
		var a = content.color,
			b = content.size,
			c = content.spec,
			d = content.model;
		var arr = [],
			cont = 0;
		var type = '';
		var col = [],
			siz = [],
			spe = [],
			mod = [];
		if (content.color) {
			if (content.color != values) {
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					addcss(arr[i].color);
					qxcss(arr[i].size);
					qxcss(arr[i].spec);
					qxcss(arr[i].model);
				}
				content.color = values;
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					change(arr[i].color);
					addcss(arr[i].size);
					addcss(arr[i].spec);
					addcss(arr[i].model);
				}
				yixuan();
			} else {
				if (content.size) {
					cont++;
					type = 'size';
				}
				if (content.spec) {
					cont++;
					type = 'spec';
				}
				if (content.model) {
					cont++;
					type = 'model';
				}
				content.color = '';
				if (content.size || content.spec || content.model) {
					arr = sx(content.color, content.size, content.spec, content.model);
					remove(arr);
					for (var i = 0; i < arr.length; i++) {
						siz.push(arr[i].size);
						col.push(arr[i].color);
						spe.push(arr[i].spec);
						mod.push(arr[i].model);
					}
					if (cont == 1) {
						if (type == 'size') {
							huifu($scope.sizelists);
						}
						if (type == 'spec') {
							huifu($scope.speclists);
						}
						if (type == 'model') {
							huifu($scope.modellists);
						}
					} else {
						siz = getArray(siz);
						spe = getArray(spe);
						mod = getArray(mod);
						huifu(siz);
						huifu(spe);
						huifu(mod);
					}
					col = getArray(col);
					for (var j = 0; j < col.length; j++) {
						addcss(col[j]);
					}
				} else {
					remove(cesi);
				}
				yixuan();
			}
		} else {
			add();
			content = {
				"color": values,
				"size": b,
				"spec": c,
				"model": d
			};
			arr = sx(content.color, content.size, content.spec, content.model);
			for (var i = 0; i < arr.length; i++) {
				change(arr[i].color);
				addcss(arr[i].size);
				addcss(arr[i].spec);
				addcss(arr[i].model);
			}
			if (content.size || content.spec || content.model) {
				content = {
					"color": a,
					"size": b,
					"spec": c,
					"model": d
				};
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					col.push(arr[i].color);
				}
				col = getArray(col);
				for (var j = 0; j < col.length; j++) {
					addcss(col[j]);
				}
			} else {
				for (var j = 0; j < $scope.colorlists.length; j++) {
					addcss($scope.colorlists[j]);
				}
			}
			content = {
				"color": values,
				"size": b,
				"spec": c,
				"model": d
			};
			yixuan();
		}
		//$scope.color = content.color;
	}
	$scope.selSize = function(values) {
		document.getElementById("btnsure").disabled = false;
		var arr = [],
			cont = 0;
		var type = '';
		var siz = [],
			col = [],
			spe = [],
			mod = [];
		var a = content.color,
			b = content.size,
			c = content.spec,
			d = content.model;
		if (content.size) {
			if (content.size != values) {
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					qxcss(arr[i].color);
					addcss(arr[i].size);
					qxcss(arr[i].spec);
					qxcss(arr[i].model);
				}
				content.size = values;
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					change(arr[i].size);
					addcss(arr[i].color);
					addcss(arr[i].spec);
					addcss(arr[i].model);
				}
				yixuan();
			} else {
				if (content.color) {
					cont++;
					type = 'color';
				}
				if (content.spec) {
					cont++;
					type = 'spec';
				}
				if (content.model) {
					cont++;
					type = 'model';
				}
				content.size = '';
				if (content.color || content.spec || content.model) {
					arr = sx(content.color, content.size, content.spec, content.model);
					remove(arr);
					for (var i = 0; i < arr.length; i++) {
						siz.push(arr[i].size);
						col.push(arr[i].color);
						spe.push(arr[i].spec);
						mod.push(arr[i].model);
					}
					if (cont == 1) {
						if (type == 'color') {
							huifu($scope.colorlists);
						}
						if (type == 'spec') {
							huifu($scope.speclists);
						}
						if (type == 'model') {
							huifu($scope.modellists);
						}
					} else {
						col = getArray(col);
						spe = getArray(spe);
						mod = getArray(mod);
						huifu(col);
						huifu(spe);
						huifu(mod);
					}
					siz = getArray(siz);
					for (var j = 0; j < siz.length; j++) {
						addcss(siz[j]);
					}
				} else {
					remove(cesi);
				}
				yixuan();
			}
		} else {
			add();
			content = {
				"color": a,
				"size": values,
				"spec": c,
				"model": d
			};
			arr = sx(content.color, content.size, content.spec, content.model);
			for (var i = 0; i < arr.length; i++) {
				change(arr[i].size);
				addcss(arr[i].color);
				addcss(arr[i].spec);
				addcss(arr[i].model);
			}
			if (content.color || content.spec || content.model) {
				content = {
					"color": a,
					"size": b,
					"spec": c,
					"model": d
				};
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					siz.push(arr[i].size);
				}
				siz = getArray(siz);
				for (var j = 0; j < siz.length; j++) {
					addcss(siz[j]);
				}
			} else {
				for (var j = 0; j < $scope.sizelists.length; j++) {
					addcss($scope.sizelists[j]);
				}
			}
			content = {
				"color": a,
				"size": values,
				"spec": c,
				"model": d
			};
			yixuan();
		}
		//$scope.size = content.size;
	}
	$scope.selSpec = function(values) {
		document.getElementById("btnsure").disabled = false;
		var arr = [],
			cont = 0;
		var type = '';
		var spe = [],
			col = [],
			mod = [],
			siz = [];
		var a = content.color,
			b = content.size,
			c = content.spec,
			d = content.model;
		if (content.spec) {
			if (content.spec != values) {
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					qxcss(arr[i].color);
					qxcss(arr[i].size);
					addcss(arr[i].spec);
					qxcss(arr[i].model);
				}
				content.spec = values;
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					addcss(arr[i].size);
					addcss(arr[i].color);
					change(arr[i].spec);
					addcss(arr[i].model);
				}
				yixuan();
			} else {
				if (content.color) {
					cont++;
					type = 'color';
				}
				if (content.size) {
					cont++;
					type = 'size';
				}
				if (content.model) {
					cont++;
					type = 'model';
				}
				content.spec = '';
				if (content.color || content.size || content.model) {
					arr = sx(content.color, content.size, content.spec, content.model);
					remove(arr);
					for (var i = 0; i < arr.length; i++) {
						siz.push(arr[i].size);
						col.push(arr[i].color);
						spe.push(arr[i].spec);
						mod.push(arr[i].model);
					}
					if (cont == 1) {
						if (type == 'color') {
							huifu($scope.colorlists);
						}
						if (type == 'size') {
							huifu($scope.sizelists);
						}
						if (type == 'model') {
							huifu($scope.modellists);
						}
					} else {
						col = getArray(col);
						siz = getArray(siz);
						mod = getArray(mod);
						huifu(col);
						huifu(siz);
						huifu(mod);
					}
					spe = getArray(spe);
					for (var j = 0; j < spe.length; j++) {
						addcss(spe[j]);
					}
				} else {
					remove(cesi);
				}
				yixuan();
			}
		} else {
			add();
			content = {
				"color": a,
				"size": b,
				"spec": values,
				"model": d
			};
			arr = sx(content.color, content.size, content.spec, content.model);
			for (var i = 0; i < arr.length; i++) {
				addcss(arr[i].size);
				addcss(arr[i].color);
				change(arr[i].spec);
				addcss(arr[i].model);
			}
			if (content.color || content.size || content.model) {
				content = {
					"color": a,
					"size": b,
					"spec": c,
					"model": d
				};
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					spe.push(arr[i].spec);
				}
				spe = getArray(spe);
				for (var j = 0; j < spe.length; j++) {
					addcss(spe[j]);
				}
			} else {
				for (var j = 0; j < $scope.speclists.length; j++) {
					addcss($scope.speclists[j]);
				}
			}
			content = {
				"color": a,
				"size": b,
				"spec": values,
				"model": d
			};
			yixuan();
		}
		//$scope.spec = content.spec;
	}
	$scope.selModels = function(values) {
		document.getElementById("btnsure").disabled = false;
		var arr = [],
			cont = 0;
		var type = '';
		var spe = [],
			col = [],
			mod = [],
			siz = [];
		var a = content.color,
			b = content.size,
			c = content.spec,
			d = content.model;
		if (content.model) {
			if (content.model != values) {
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					qxcss(arr[i].color);
					qxcss(arr[i].size);
					qxcss(arr[i].spec);
					addcss(arr[i].model);
				}
				content.model = values;
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					addcss(arr[i].size);
					addcss(arr[i].color);
					addcss(arr[i].spec);
					change(arr[i].model);
				}
				yixuan();
			} else {
				qxcss(values);
				if (content.color) {
					cont++;
					type = 'color';
				}
				if (content.size) {
					cont++;
					type = 'size';
				}
				if (content.spec) {
					cont++;
					type = 'spec';
				}
				content.model = '';
				if (content.color || content.size || content.spec) {
					arr = sx(content.color, content.size, content.spec, content.model);
					remove(arr);
					for (var i = 0; i < arr.length; i++) {
						siz.push(arr[i].size);
						col.push(arr[i].color);
						spe.push(arr[i].spec);
						mod.push(arr[i].model);
					}
					if (cont == 1) {
						if (type == 'color') {
							huifu($scope.colorlists);
						}
						if (type == 'size') {
							huifu($scope.sizelists);
						}
						if (type == 'spec') {
							huifu($scope.speclists);
						}
					} else {
						col = getArray(col);
						siz = getArray(siz);
						spe = getArray(spe);
						huifu(col);
						huifu(siz);
						huifu(spe);
					}
					mod = getArray(mod);
					for (var j = 0; j < mod.length; j++) {
						addcss(mod[j]);
					}
				} else {
					remove(cesi);
				}
				yixuan();
			}
		} else {
			add();
			content = {
				"color": a,
				"size": b,
				"spec": c,
				"model": values
			};
			arr = sx(content.color, content.size, content.spec, content.model);
			for (var i = 0; i < arr.length; i++) {
				addcss(arr[i].size);
				addcss(arr[i].color);
				addcss(arr[i].spec);
				change(arr[i].model);
			}
			if (content.color || content.size || content.spec) {
				content = {
					"color": a,
					"size": b,
					"spec": c,
					"model": d
				};
				arr = sx(content.color, content.size, content.spec, content.model);
				for (var i = 0; i < arr.length; i++) {
					mod.push(arr[i].model);
				}
				mod = getArray(mod);
				for (var j = 0; j < mod.length; j++) {
					addcss(mod[j]);
				}
			} else {
				for (var j = 0; j < $scope.modellists.length; j++) {
					addcss($scope.modellists[j]);
				}
			}
			content = {
				"color": a,
				"size": b,
				"spec": c,
				"model": values
			};
			yixuan();
		}
		//$scope.models = content.model;
	}

	function huifu(arry) {
		for (var i = 0; i < arry.length; i++) {
			addcss(arry[i]);
		}
	}

	function yixuan() {
		if (content.color) {
			change(content.color);
		}
		if (content.size) {
			change(content.size);
		}
		if (content.spec) {
			change(content.spec);
		}
		if (content.model) {
			change(content.model);
		}
	}

	function add() {
		for (var i = 0; i < cesi.length; i++) {
			qxcss(cesi[i].color);
			qxcss(cesi[i].size);
			qxcss(cesi[i].spec);
			qxcss(cesi[i].model);
		}
	}

	function remove(arry) {
		for (var i = 0; i < arry.length; i++) {
			addcss(arry[i].color);
			addcss(arry[i].size);
			addcss(arry[i].spec);
			addcss(arry[i].model);
		}
	}

	function change(values) { //选中
		if (values) {
			document.getElementById(values).style.color = "#e23308";
			document.getElementById(values).style.borderColor = "#e23308";
			document.getElementById(values).removeAttribute("disabled");
		}
	}

	function addcss(csms) { //可选
		if (csms) {
			document.getElementById(csms).style.color = "#666";
			document.getElementById(csms).style.borderColor = "#666";
			document.getElementById(csms).removeAttribute("disabled");
		}
	}

	function qxcss(csms) { //不可选
		if (csms) {
			document.getElementById(csms).style.color = "#ccc";
			document.getElementById(csms).style.borderColor = "#ccc";
			document.getElementById(csms).setAttribute("disabled", "true");
		}
	}
	//颜色尺寸筛选
	function sx(col, siz, spe, mod) {
		document.getElementById("btnsure").disabled = false;
		var arry = [];
		if (col) {
			if (siz) {
				if (spe) {
					if (mod) {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].color == col && cesi[i].size == siz && cesi[i].spec == spe && cesi[i].model == mod) {
								arry.push(cesi[i]);
							}
						}
					} else {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].color == col && cesi[i].size == siz && cesi[i].spec == spe) {
								arry.push(cesi[i]);
							}
						}
					}
				} else {
					if (mod) {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].color == col && cesi[i].size == siz && cesi[i].model == mod) {
								arry.push(cesi[i]);
							}
						}
					} else {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].color == col && cesi[i].size == siz) {
								arry.push(cesi[i]);
							}
						}
					}
				}
			} else {
				if (spe) {
					if (mod) {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].color == col && cesi[i].spec == spe && cesi[i].model == mod) {
								arry.push(cesi[i]);
							}
						}
					} else {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].color == col && cesi[i].spec == spe) {
								arry.push(cesi[i]);
							}
						}
					}
				} else {
					if (mod) {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].color == col && cesi[i].model == mod) {
								arry.push(cesi[i]);
							}
						}
					} else {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].color == col) {
								arry.push(cesi[i]);
							}
						}
					}
				}
			}
		} else {
			if (siz) {
				if (spe) {
					if (mod) {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].size == siz && cesi[i].spec == spe && cesi[i].model == mod) {
								arry.push(cesi[i]);
							}
						}
					} else {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].size == siz && cesi[i].spec == spe) {
								arry.push(cesi[i]);
							}
						}
					}
				} else {
					if (mod) {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].size == siz && cesi[i].model == mod) {
								arry.push(cesi[i]);
							}
						}
					} else {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].size == siz) {
								arry.push(cesi[i]);
							}
						}
					}
				}
			} else {
				if (spe) {
					if (mod) {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].spec == spe && cesi[i].model == mod) {
								arry.push(cesi[i]);
							}
						}
					} else {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].spec == spe) {
								arry.push(cesi[i]);
							}
						}
					}
				} else {
					if (mod) {
						for (var i = 0; i < cesi.length; i++) {
							if (cesi[i].model == mod) {
								arry.push(cesi[i]);
							}
						}
					}
				}
			}
		}
		return arry;
	}

	$scope.productGz = function() {
		//获取当前商品关注状态
		if (!gouwuche)
			return;
		var flag = $scope.guanzhustatus;
		if (!flag)
			return;
		urlgz = getUrl("52productGz");
		headergz = getHeader();
		paramsgz = 'accountId=' + readData(localStorage.account) + '&productId=' + readData(localStorage.goodsId) + '&flag=' + flag;
		plus.nativeUI.showWaiting('请稍等...');
		$http({
			method: 'POST',
			url: urlgz,
			headers: headergz,
			timeout: 10000,
			//cache: true,
			data: paramsgz
		}).success(function(data, status, headers, config) {
			//刷新我的关注
			//buyCarNum('2');
			if (data.code == 0) {
				if (flag == 1) {
					$scope.status = "取消关注";
					$scope.guanzhustatus = 2;
					document.getElementById("statusImg").src = "../../image/shopping/guanzhu.png";
				} else {
					$scope.status = "加关注";
					$scope.guanzhustatus = 1;
					document.getElementById("statusImg").src = "../../image/shopping/weiguanzhu.png";
				}
			} else {
				console.log("商品详情加关注" + data.msg);
			}
			plus.nativeUI.closeWaiting();
		}).error(function() {
			plus.nativeUI.closeWaiting();
			console.log("商品详情加关注出错");
		});
	}
	$scope.goodsNumber = function() {
		//购物车商品数量
		var obuycarnums = document.getElementById("buyNum");
		if (localStorage.buyCar && readDataBuyCar(localStorage.buyCar) != "") {
			var buyCar = eval('(' + readDataBuyCar(localStorage.buyCar) + ')');
			var buyCarGuide = buyCar[readData(localStorage.guideId)];
			var num = 0
				//遍历购物车，查看商品是否存在（同型号同颜色）
			for (x in buyCarGuide) {
				num = num + parseInt(buyCarGuide[x]['number'])
			}
			if (num > 0) {
				obuycarnums.innerText = num;
				obuycarnums.style.display = "block";
			} else {
				obuycarnums.style.display = "none";
			}
		}
	}
	$scope.goodsNumber();
	//立即购买sureArguments
	function notSelect() {
		var cont = '';
		if (color.length > 0) {
			if (!sureArguments.color) {
				cont = ' 颜色  ';
			}
		}
		if (size.length > 0) {
			if (!sureArguments.size) {
				cont += ' 尺码  ';
			}
		}
		if (spec.length > 0) {
			if (!sureArguments.spec) {
				cont += ' 规格  ';
			}
		}
		if (model.length > 0) {
			if (!sureArguments.model) {
				cont += ' 型号  ';
			}
		}
		return cont;
	}
	$scope.buyNow = function() {
		//检查参数完整性
		if (!gouwuche)
			return;
		var cont = notSelect();
		if (cont) {
			cont = "请选择" + cont;
			paramerState = 'buyNow';
			tishi(cont);
		} else {
			paramerState = null;
			var yincang, jsd = [];
			if ($scope.products.priceName) {
				yincang = true;
			} else {
				yincang = false;
			}
			jsd.push({
				id: goodsId,
				name: $scope.products.name,
				picture: $scope.products.picture,
				number: $scope.productNum,
				price: $scope.products.price,
				nowPrice: $scope.products.nowPrice,
				specColorpr: $scope.color,
				specSizepr: $scope.size,
				specModel: $scope.models,
				specSpec: $scope.spec,
				priceName: $scope.products.priceName,
				deposit: $scope.products.deposit,
				hide: yincang
			});
			if (jsd[0].specColorpr) {
				jsd[0].ngcolor = "false";
			} else {
				jsd[0].ngcolor = "true";
			}
			if (jsd[0].specSizepr) {
				jsd[0].ngsize = "false";
			} else {
				jsd[0].ngsize = "true";
			}
			if (jsd[0].specSpec) {
				jsd[0].ngspec = "false";
			} else {
				jsd[0].ngspec = "true";
			}
			if (jsd[0].specModel) {
				jsd[0].ngmodel = "false";
			} else {
				jsd[0].ngmodel = "true";
			}
			jsd = {
				list: jsd,
				ljgm: 1
			};
			localStorage.order = writeData(JSON.stringify(jsd));
			mui.openWindow({
				url: 'conformOrder.html',
				id: 'conformOrder.html',
				waiting: {
					autoShow: false
				}
			});
		}
	}
	window.addEventListener("refreshBuyCar", function() {
		$scope.goodsNumber();
	}, false)
}